<template>
	<div class="zxmyContent">
        <!--头部-->
		<!--<header class="aui-bar aui-bar-nav aui-bar-light">
			<div class="go-back" @click="goBack">
				<i></i>
				<i></i>
				<i></i>
			</div>
			<div class="aui-title">商品信息</div>
		</header>-->
		<!-- <my-header :title="'商品信息'" :hasTitle="true" :hasBack="true" ></my-header> -->
        <my-header :title="'商品信息'"  :hasBacks="true" :goBack="goBack" :canteen ="true"></my-header>
		<!--<div style="height:2rem;"></div>-->
		<div style="flex:1;overflow-y:auto;overflow-x: hidden;">
			<!--商品列表-->
			<!-- <div style="width: 100%;height: 1500px;background: red;">
				<div style="width: 100%;height: 300px;background: yellow;"></div>
				<div style="width: 100%;height: 300px;background: green;"></div>
				<div style="width: 100%;height: 300px;background: blue;"></div>
				<div style="width: 100%;height: 300px;background: black;"></div>
				<div style="width: 100%;height: 300px;background: pink;"></div>
			</div> -->
			<!-- <div class="aui-content"> 导致滑动卡顿故注释 -->
				<!-- <ul class="aui-list aui-media-list commodity_list subtotal_list" v-if="dataList && dataList[0] && dataList[0].length"> -->
				<ul class="aui-list aui-media-list commodity_list subtotal_list" >
					<li class="aui-list-item baoguo-title">
						<div class="aui-list-item-inner" style="text-align: left;">
							<span >{{'档口：'}}</span>&nbsp;&nbsp;
                            <span>海鲜造物</span>
							<!-- <span style="color: #ef5432;" v-if="getDateNormal && getOrderFlag">{{getSendTime(0)}}&nbsp;送达</span> -->
							<div class="aui-pull-right text_c_gray" >共<span>{{goodsNum(dataList[0])}}</span>件</div>
						</div>
					</li>
					<li class="aui-list-item baoguo-list-item baoguo-root" v-for="(item,index) in dataList[0]" :key='index'>
						<div class="aui-media-list-item-inner">
							<div class="aui-list-item-media" style="width:4.3125rem;height:4.3125rem ">
								<div class="goodsTopShow" v-if="item.buyType == 2 || item.buyType == 3" :class="{goodsTopShowBackY:item.buyType == 2,goodsTopShowBackR:item.buyType == 3}">
                                    {{item.buyType == 2?'加价购':'赠品'}}
                                </div>
								<img v-lazy="item.goodsImg || goodsImg(item) || 'static/image/demo2.png'" alt="" />

							</div>
							<div class="aui-list-item-inner suggest" style="text-align: left;height: 5.3125rem;">
								<h3 :style="item.workingInfo?'margin-bottom: 0.3rem;':'margin-bottom: 0.75rem;'">{{item.goodsname || item.goodsName}}</h3>
								<p v-if="item.workingInfo">加工服务：{{getAdd(item)}}</p>
								<p style="min-height:1rem;">{{getGoodsspec(item)}}</p>
								<p style="position:absolute;bottom:0;left:0.5rem;">¥{{getSingerPricely(item)}}</p>
							</div>
							<div class="subtotal" style="width: 38%;height:5.3125rem;">
								<a style=" display: block;" v-if="compareMoney(item)">¥{{getSingerPrices(item)}}</a>
								<span style="display: inline-block;text-decoration:line-through;height:2.8rem;color: #ccc;font-size:0.5rem;"  v-if="compareMoney(item)">¥{{getSingerPrice(item)}}</span>
								<span style="display: inline-block;height:2.8rem;"  v-if="compareMoneys(item)">¥{{getSingerPrice(item)}}</span>
								<p style="position:absolute;bottom:0;right:0.5rem;"><span v-if="item.goodsType != 7" style="display: inline-block;height:0;">x{{getGoodsSinger(item)}}</span><span v-if="item.goodsType == 7" style="display: inline-block;height:0;">{{getGoodsSinger(item)}}kg</span></p>
							</div>
							
						</div>
					</li>
				</ul>
				
			<!-- </div> -->
			<!--商品列表 end-->
		</div>
	</div>

</template>

<script>

import {mapGetters,mapMutations} from "vuex";
import Header from "../header";
import axios from "axios";
	export default {
	  	name: 'hello',
	  	data () {
	    	return {
				msg: '这是新增地址页面',
	            page: "CommodityInformation",
	            componentName: "CommodityInformation",
	            dataList: [],
	            num:null,
	            type:'',
	            flag:false, // 是否同时存在大家爱你和常规商品两个包裹
			}
		},
		computed: {
			...mapGetters('zx',[
				"getDateNormal","getDateBig","getTimeNormal","getTimeBig","getOrderFlag"
			])
		},
		components: {
	       "my-header": Header
	    },
	    methods: {
	    	//获取配送时间用于展示
	    	getSendTime(num){
	    		var str = '';
	    		var getTimeNormal = this.getTimeNormal;
	    		var getTimeBig = this.getTimeBig;
	    		//0 代表常规的包裹  1 代表大件的包裹
	    		if(num === 0){
	    			if(this.dataList && this.dataList[0] && this.dataList[0].length){
	    				var sendDate = this.getDateNormal;
	    				var startBookTm = this.getTime(getTimeNormal.startBookTm);
	    				var endBookTm = this.getTime(getTimeNormal.endBookTm);
	    				console.log(sendDate,startBookTm,endBookTm)
	    				str = sendDate + " " + startBookTm + "-" + endBookTm;
	    			}

	    		}else if(num === 1){
	    			if(this.dataList && this.dataList[1] && this.dataList[1].length){
	    				var sendDate = this.getDateBig;
	    				var startBookTm = this.getTime(getTimeBig.startBookTm);
	    				var endBookTm = this.getTime(getTimeBig.endBookTm);
	    				str = sendDate + " " + startBookTm + "-" + endBookTm;
	    				console.log(sendDate,startBookTm,endBookTm)
	    			}
	    		}
	    		return str;
	    	},
	    	//转换时间格式
			getTime(param) {

				if(param) {
					let date = new Date(param);
					let year = date.getFullYear();
					let month = checkTime(date.getMonth() + 1);
					let day = checkTime(date.getDate());
					let hour = checkTime(date.getHours());
					let min = checkTime(date.getMinutes());
					let sec = checkTime(date.getSeconds());

					function checkTime(i) {
						if(i < 10) {
							i = '0' + i;
						}
						return i;
					}

					return hour + ':' + min;
				} else {
					return '';
				}
			},
	    	getGoodsspec(item){

	    		if(item.goodsType == 6){
	    			var str = "约" +  Number(item.weighingsmall) + "~" +  Number(item.weighingbig)
	    			var str2 = item.goodsunit + '/' + item.mallUnit;
//	    			console.log(str,str2,9999)
	    			if(str && item.goodsunit && item.mallUnit){
	    				return str + str2;
	    			}else if(item.weighingsmall && item.weighingbig){
	    				return str;
	    			}else{
	    				return ''
	    			}

	    		}else{
	    			return item.goodsspec || '';
	    		}
	    	},
	    	// getSingerPrice(item){
	    	// 	if(item.goodsType == 6){
	    	// 		var str = '';
	    	// 		if(item.mallUnit){
	    	// 			str = (Number(item.wsprice) * Number(item.weighingbig)).toFixed(2)+'/'+item.mallUnit;
	    	// 		}else{
	    	// 			str = (Number(item.wsprice) * Number(item.weighingbig)).toFixed(2)
	    	// 		}
	    	// 		return str || '';
	    	// 	}else{
	    	// 		let str = Number(item.wsprice).toFixed(2) + '/' + item.goodsunit;
	    	// 		return str || '';
	    	// 	}
			// },
			 getSingerPricely(item){
	    		if(item.goodsType == 6){
	    			var str = '';
	    			if(item.mallUnit){
	    				str = (Number(item.wsprice) * Number(item.weighingbig)).toFixed(2)+'/'+item.mallUnit;
	    			}else{
	    				str = (Number(item.wsprice) * Number(item.weighingbig)).toFixed(2)
	    			}
	    			return str || '';
	    		}else{
	    			let str = Number(item.wsprice).toFixed(2) + '/' + item.goodsunit;
	    			return str || '';
	    		}
			},
			getSingerPrice(item){//原价小计金额
	    		if(item.buyType == 1){
	    			var str = '';
	    			if(item.mallUnit){
	    				str = Number(item.promTotalMoney ).toFixed(2);
	    			}else{
	    				str = Number(item.promTotalMoney ).toFixed(2)
	    			}
	    			return str || '';
	    		}else{
	    			let str = Number(item.totalMoney ).toFixed(2);
	    			return str || '';
				}
			},
			getSingerPrices(item){//优惠后的总金额
	    		if(item.buyType == 1){
	    			var str = '';
	    			if(item.mallUnit){
	    				str = Number(item.realTotalMoney).toFixed(2);
	    			}else{
	    				str = Number(item.realTotalMoney).toFixed(2)
	    			}
	    			return str || '';
	    		}else{
	    			let str = Number(item.realTotalMoney ).toFixed(2);
	    			return str || '';
	    		}
			},
			//比较价格
			compareMoney(item){
				// console.log("12345678910",this.getSingerPrices(item),this.getSingerPrice(item),this.getSingerPrices(item) - this.getSingerPrice(item))
				if(this.getSingerPrices(item) - this.getSingerPrice(item) < 0){
					return true
				}else{
					return false
				}
			},
			//比较价格
			compareMoneys(item){
				// console.log("12345678910",this.getSingerPrices(item),this.getSingerPrice(item),this.getSingerPrices(item) - this.getSingerPrice(item))
				if(this.getSingerPrices(item) - this.getSingerPrice(item) == 0){
					return true
				}else{
					return false
				}
			},
	    	getAdd(item){
	    		if(item.workingInfo){
	    			return JSON.parse(item.workingInfo).processingattribute
	    		}
	    	},
	    	getDateList(){
	    		this.dataList = this.$route.query.arr;
	    		console.log(this.$route.query.arr,"11122299632-----------------------------------------");
//	    		console.log(this.$route.query.obj);
	    		if(this.$route.query.obj){
	    			this.type = this.$route.query.obj.type;
	    			this.flag = this.$route.query.obj.flag;
	    		}
	    	},
	    	goBack(){
	    		window.history.back()
	    	},
	    	goodsImg(goodsItemData) {
	            if (goodsItemData && goodsItemData.urllist) {
	                if(goodsItemData.urllist.length) {
	                	for(let i = 0 ; i < goodsItemData.urllist.length; i++){
	                		if(goodsItemData.urllist[i].Imgurltype == 1){
	                			return goodsItemData.urllist[i].imgurl || "static/image/demo2.png";
	                		}
	                	}
	                } else {
	                    return "static/image/demo2.png";
	                }
	            } else {
	                return "static/image/demo2.png";
	            }
	        },
	        goodsNum(arr) {
	        	console.log(arr,'散卖')
	        	var num = 0;
	        	if(arr && arr.length != 0){
	        		for(let i = 0 ; i < arr.length; i++){
		            	if(arr[i].goodsType == 7){

							num += 1
							console.log(num,'散卖1')
						}else{
							num += arr[i].goodsNum;
							console.log(num,'散卖2')
						}
		            }
	        	}
	        	console.log(num,'散卖2')
	        	return num;
	        },
	        getGoodsSinger(item){
	        	//ladderqty  阶梯重量  minsaleqty 起售重量
	        	if(item.goodsType == 7){
					if(item.goodsNum == 1){
						return Math.round(Number(item.minsaleqty) * 100) / 100;  
					}else{
						var str = item.minsaleqty + (Number(item.goodsNum) - 1) * item.ladderqty;
						return Math.round(Number(str) * 100) / 100; 
					}
	        	}else {
	        		return Math.round(Number(item.goodsNum) * 100) / 100; 
	        	}
	        }
	    },
		async created () {
			await this.getDateList();
		},
		mounted () {
			this.goodsNum();
		},
		updated() {

		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	.subtotal_list .aui-list-item-media {
	    width: 22vw;
	    height: 22vw;
	}
	.commodity_list .suggest h3 {
	    font-size: 0.7rem;
	    min-height: 1.5rem;
		/* overflow: hidden;
        white-space: nowrap;
    	text-overflow: ellipsis; */
	}
	.subtotal {
		/* overflow: hidden;
        white-space: nowrap;
    	text-overflow: ellipsis; */
	}
	.zxmyContent{
		width: 100%;
	    height: 100%;
	    display: flex;
	    flex-direction: column;
	    justify-content: space-between;
	}
    .goodsTopShow{
        opacity: 0.6;
        position: absolute;
        left: 0;top: 0;
        color: #ffffff;
        padding: 0 0.1rem;
        font-size:12px;
    }
    .goodsTopShowBackY{
        background:#faa73c;
    }
    .goodsTopShowBackR{
        background: #EF5423;
    }
</style>
